<template>
  <el-card>
    <el-button @click="$refs.dialog.visible = true" type="primary" round plain
      >新增</el-button
    >
    <el-divider></el-divider>
    <el-table
      :data="menuList"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <!-- <el-table-column prop="id" label="id" min-width="80"></el-table-column> -->
      <el-table-column
        prop="title"
        label="名称"
        min-width="180"
      ></el-table-column>
      <el-table-column
        prop="url"
        label="地址"
        min-width="180"
      ></el-table-column>
      <el-table-column label="操作" min-width="180">
        <template v-slot="props">
          <el-button @click="edit(props.row)" type="success" size="mini" round plain>编辑</el-button>
          <el-button
            @click="del(props.row)"
            type="danger"
            size="mini"
            round
            plain
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <MenuDialog ref="dialog" />
  </el-card>
</template>

<script>
import MenuDialog from "./MenuDialog";
import { mapState, mapMutations } from "vuex";
export default {
  components: {
    MenuDialog,
  },
  computed: {
    ...mapState(["menuList"]),
  },
  data() {
    return {};
  },
  methods: {
    ...mapMutations(["menuDel"]),
    edit(row){
      // 显示对话框组件
      this.$refs.dialog.visible=true;
      // 将待编辑id菜单数据传递给对话框组件
      this.$refs.dialog.getMenuData(row);
    },
    del(row) {
      this.menuDel(row);
    },
  },
};
</script>

<style>
</style>